<template>
  <div class="PageContent">
      <div class="PageItem">
        <el-row :gutter="20" class="el_row">
          <el-col :span="4" style="height: 100%" class="el_col">
            <el-tree
              ref="organizationtree"
              :data="treeData"
              node-key="id"
              default-expand-all
              :props="defaultProps"
              :expand-on-click-node="false"
              v-if="lastTreeData.length>0"
              @node-click="handleClick"
              :default-expanded-keys="[lastTreeData[0].id]"
              :default-checked-keys="[lastTreeData[0].id]"
            >
            </el-tree>
            <div v-else class="empty">
              <img :src="require('../../../static/images/empty.png')" alt="">
              <h4>暂无数据</h4>
            </div>
          </el-col>
          <el-col :span="20" class="el_col right_col">
            <div class="list_wrapper" v-if="wakeHalls.length > 0">
              <el-row :gutter="20">
                <el-col class="list_item" :span="6" v-for="(item, index) in wakeHalls" :key="index">
                  <el-card
                    shadow="hover"
                    :class="item.depositCaseState==1 ? 'saled' : 'free'"
                    :style="item.flag ? 'background-color:lightgreen' : ''"
                    @click.stop="mournSelect(item, index)"
                  >
                    <div class="card_header">
                      <div class="item_item">
                        <span>格位编号：</span>
                        <span>{{ item.positionName }}</span>
                      </div>
                      <div class="item_type">
                        <span>格位类型：</span>
                        <span>{{item.depositCaseCode | formatType}}</span>
                      </div>
                    </div>
                    <!-- 单格位且满了 -->
                    <div class="card_content" v-if="item.depositCaseCode==1&&item.depositCaseState==1">
                      <div class="dead_person_conent">
                        <div class="dead_person" v-for="(dead,index) in item.currentDeadSaveEntities" :key='index'>
                          <div class="dead_content">
                            <span>逝者姓名：</span>
                            <span>{{ dead.deadName }}</span>
                          </div>
                          <div class="dead_btns">
                            <!-- <div class="dead_btn" v-if="btnRight.btnModifyBuryingInfo" @click="modifyBuryingInfo(dead.businessCode)"><span>修改</span></div> -->
                            <div class="dead_btn" v-if="btnRight.btnCheckBuryingInfo" @click="checkBuryingInfo(dead.businessCode,dead.inBusinessId,dead.saveId)"><span>查看</span></div>
                          </div>
                        </div>
                      </div>
                    </div>
                    <!-- 单格位且空 -->
                    <div class="card_content" v-if="item.depositCaseCode==1&&item.depositCaseState==0">
                       <div class="dead_person_conent">
                        <div class="dead_person">
                          <div class="dead_content">
                          </div>
                          <div class="dead_btn" v-if="btnRight.btnAddBuyerInfo"  @click="addBuyerInfo(item.id)"><span>增加安葬人</span></div>
                        </div>
                       </div>
                    </div>
                    <!-- 双格位且满了 -->
                    <div class="card_content" v-if="item.depositCaseCode==2&&item.depositCaseState==1">
                        <div class="dead_person_conent">
                          <div class="dead_person" v-for="(dead,index) in item.currentDeadSaveEntities" :key='index'>
                            <div class="dead_content">
                              <span>逝者姓名：</span>
                              <span>{{ dead.deadName }}</span>
                            </div>
                            <div class="dead_btns">
                              <!-- <div class="dead_btn" v-if="btnRight.btnModifyBuryingInfo"  @click="modifyBuryingInfo(dead.businessCode)"><span>修改</span></div> -->
                              <div class="dead_btn" v-if="btnRight.btnCheckBuryingInfo" @click="checkBuryingInfo(dead.businessCode,dead.inBusinessId,dead.saveId)"><span>查看</span></div>
                            </div>
                          </div>
                        </div>
                    </div>
                    <!-- 双格位且不满 -->
                    <div class="card_content" v-if="item.depositCaseCode==2&&item.depositCaseState==0">
                         <!-- 双格位都空着 -->
                         <div class="dead_person_conent" v-if="item.currentDeadSaveEntities.length==0">
                           <div class="dead_person" v-for="(dead,index) in item.depositCaseCode" :key='index'>
                            <div class="dead_content">
                              <!-- <span>逝者姓名：</span>
                              <span>{{ dead.deadName }}</span> -->
                            </div>
                            <div class="dead_btn" v-if="btnRight.btnAddBuyerInfo" @click="addBuyerInfo(item.id)"><span>增加安葬人</span></div>
                           </div>
                         </div>
                         <!-- 双格位不空且不满 -->
                         <div class="dead_person_conent" v-if="item.currentDeadSaveEntities.length>0">
                           <!-- 现有的 -->
                           <div class="dead_person has_person" v-for="dead in item.currentDeadSaveEntities" :key='dead.id'>
                            <div class="dead_content">
                              <span>逝者姓名：</span>
                              <span>{{ dead.deadName }}</span>
                            </div>
                            <div class="dead_btns">
                              <!-- <div class="dead_btn" v-if="btnRight.btnModifyBuryingInfo"  @click="modifyBuryingInfo(dead.businessCode)"><span>修改</span></div> -->
                              <div class="dead_btn" v-if="btnRight.btnCheckBuryingInfo" @click="checkBuryingInfo(dead.businessCode,dead.inBusinessId,dead.saveId)"><span>查看</span></div>
                            </div>
                           </div>
                           <!-- 空着的 -->
                          <div class="dead_person" v-for="(dead,index) in (item.depositCaseCode-item.currentDeadSaveEntities.length)" :key='index'>
                              <div class="dead_content">
                              
                              </div>
                              <div class="dead_btn" v-if="btnRight.btnAddBuyerInfo" @click="addBuyerInfo(item.id)"><span>增加安葬人</span></div>
                            </div>
                         </div>
                    </div>
                  </el-card>
                </el-col>
              </el-row>
            </div>
            <div v-else class="empty">
              <img :src="require('../../../static/images/empty.png')" alt="">
              <h4>暂无数据</h4>
            </div>
          </el-col>
        </el-row>
    </div>
    <!-- 安葬人信息维护 -->
    <el-dialog title="安葬人信息维护" :visible.sync="BuyerInfoDialogVisible" width="80%" v-dialogDrag border @close="closeDialog">
      <el-form
        :model="ruleForm"
        :inline="true"
        ref="ruleForm"
        :rules="rules"
        @submit.native.prevent
        :disabled='BuyerInfoFormDisabled'
        label-width="100px"
      >
        <div class="PageItem">
          <el-row class="PageInfo"><i class="info-bar"></i>逝者信息</el-row>
          <el-row class="paddingleft2em">
            <el-col :span="6">
              <el-form-item label="姓名" prop="funeralDead.deadName">
              <el-input
                v-model="ruleForm.funeralDead.deadName"
                minlength="2"
                maxlength="50"
                :title="ruleForm.funeralDead.deadName"
                placeholder="姓名"
              >
              </el-input>
            </el-form-item>
            <el-form-item label="　民族">
                <el-select
                  v-model="ruleForm.funeralDead.deadNationCode"
                  @focus="focus"
                  @clear="clear"
                  clearable
                  filterable
                  :filter-method="PinyinMatchnation"
                  placeholder="请选择民族"
                  class="w150"
                >
                  <el-option
                    v-for="item in copydictionary.nation"
                    :key="item.dataCode"
                    :label="item.dataText"
                    :value="item.dataCode"
                    :disabled="item.disableState"
                  />
                </el-select>
            </el-form-item>
            <el-form-item label="　户籍地">
              <el-input
                v-model="ruleForm.funeralDead.householdRegistrationPlace"
                class="w425"
                placeholder="请填写户籍地"
              ></el-input>
            </el-form-item>
             
            </el-col>
            <el-col :span="6">
               <el-form-item label="　性别">
              <el-select
                v-model="ruleForm.funeralDead.deadGenderCode"
                @focus="focus"
                @clear="clear"
                clearable
                filterable
                :filter-method="PinyinMatchsex"
                placeholder="请选择性别"
                class="w150"
              >
                <el-option
                  v-for="item in copydictionary.sex"
                  :key="item.dataCode"
                  :label="item.dataText"
                  :value="item.dataCode"
                  :disabled="item.disableState"
                />
              </el-select>
               </el-form-item>
               <el-form-item label="　证件类型">
              <el-select
                v-model.number="ruleForm.funeralDead.certificateTypeCode"
                @focus="focus"
                @clear="clear"
                clearable
                filterable
                :filter-method="PinyinMatchcertificates"
                placeholder="请选择证件类型"
                class="w150"
              >
                <el-option
                  v-for="item in copydictionary.certificates"
                  :key="item.dataCode"
                  :label="item.dataText"
                  :value="item.dataCode"
                  :disabled="item.disableState"
                />
              </el-select>
            </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="　出生日期" prop="funeralDead.birthDate">
                <el-date-picker
                  type="date"
                  v-model="ruleForm.funeralDead.birthDate"
                  placeholder="选择日期"
                  class="w150"
                  :picker-options="pickerOptions"
                ></el-date-picker>
              </el-form-item>
              <el-form-item label="　证件号码">
                <el-input
                  v-model="ruleForm.funeralDead.certificateNo"
                  maxlength="20"
                  :title="ruleForm.name"
                  placeholder="请填写证件号码"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="　国籍">
                <el-select
                  v-model="ruleForm.funeralDead.countryCode"
                  @focus="focus"
                  @clear="clear"
                  clearable
                  filterable
                  :filter-method="PinyinMatchnationality"
                  placeholder="请选择国籍"
                  class="w150"
                >
                  <el-option
                    v-for="item in copydictionary.nationality"
                    :key="item.dataCode"
                    :label="item.dataText"
                    :value="item.dataCode"
                    :disabled="item.disableState"
                  />
                </el-select>
              </el-form-item>
              <el-form-item
              label="　死亡日期"
              prop="funeralDead.deathDate"
              >
              <el-date-picker
                v-model="ruleForm.funeralDead.deathDate"
                type="date"
                placeholder="选择日期"
                class="w150"
                style="width: 100px"
                :picker-options="pickerOptions"
              ></el-date-picker>
            </el-form-item>
            </el-col>
          </el-row>
        </div>
        <div class="PageItem">
          <el-row class="PageInfo"><i class="info-bar"></i>经办人信息</el-row>
          <el-row class="paddingleft2em">
            <el-col :span="6">
              <el-form-item label="　姓名">
                <el-input
                  v-model="ruleForm.depositBuryAgentEntity.familyName"
                  minlength="2"
                  maxlength="50"
                  placeholder="请填写姓名"
                >
                </el-input>
            </el-form-item>
            <el-form-item label="　联系地址">
              <el-input
                v-model="ruleForm.depositBuryAgentEntity.familyAddress"
                maxlength="50"
                class="w1230"
                placeholder="请填写联系地址"
              ></el-input>
            </el-form-item>
            </el-col>
            <el-col :span="6">
               <el-form-item
              label="手机号码"
              prop="depositBuryAgentEntity.familyPhone"
              
            >
              <el-input
                v-model="ruleForm.depositBuryAgentEntity.familyPhone"
                @mousewheel.native.prevent
                onkeyup="value=value.replace(/[^\d]/g,'')"
                maxlength="11"
                placeholder="请填写手机号码"
              ></el-input>
            </el-form-item>
            </el-col>
            <el-col :span='6'>
              <el-form-item
              label="证件类型"
              prop="depositBuryAgentEntity.certificateTypeCode"
              
            >
              <el-select
                v-model="ruleForm.depositBuryAgentEntity.certificateTypeCode"
                @focus="focus"
                @clear="clear"
                clearable
                filterable
                :filter-method="PinyinMatchcertificates"
                placeholder="请选择证件类型"
                class="w150"
              >
                <el-option
                  v-for="item in copydictionary.certificates"
                  :key="item.dataCode"
                  :label="item.dataText"
                  :value="item.dataCode"
                  :disabled="item.disableState"
                />
              </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item
              label="证件号码"
              prop="depositBuryAgentEntity.certificateNo"
              
            >
              <el-input
                v-model="ruleForm.depositBuryAgentEntity.certificateNo"
                maxlength="20"
                placeholder="请填写证件号码"
              ></el-input>
            </el-form-item>
            </el-col>
          </el-row>
        </div>
        <div class="PageItem" v-if='isCheck'>
          <el-row class="paddingleft2em pt20">
            <el-col :span="6">
              <el-form-item label="图片" v-if="ruleForm.images&&ruleForm.images.length>0">
                <el-image
                  class="el_img"
                  fit='fill'
                  style="width: 100px; height: 100px"
                  v-for="(item,index) in ruleForm.images"
                  :key="index"
                  :src="item" 
                  :preview-src-list="ruleForm.images">
                </el-image>
            </el-form-item>
            <el-form-item label="图片" v-else>
              <el-image
                fit='fill'
                 class="el_img"
                style="width: 100px; height: 80px"
                :src="require('../../../static/images/noImg.png')" >
              </el-image>
            </el-form-item>
            </el-col>
          </el-row>
        </div>
        <div>
          <!-- <el-row>
            <el-col :span="4" :offset="20" v-if='!BuyerInfoFormDisabled'>
              <el-form-item>
                <el-button type="primary" @click="saveBuyerInfoFormData('ruleForm')">保 存</el-button>
                <el-button type="primary"  @click="BuyerInfoDialogVisible = false">关 闭</el-button>
              </el-form-item>
            </el-col>
          </el-row> -->
        </div>
      </el-form>
      <span slot="footer" class="dialog-footer" >
        <el-button type="primary" v-if="!isCheck" @click="saveBuyerInfoFormData('ruleForm')">保 存</el-button>
        <el-button type="primary"  @click="BuyerInfoDialogVisible = false">关 闭</el-button>
      </span>
    </el-dialog>
    <!-- 查看所有逝者信息 -->
    <!-- <el-dialog
      title="逝者信息"
      :visible.sync="deadInfoDialogVisible"
      v-dialogDrag border
      width="80%">
      <ul>
        <li v-for="(item,index) in selectDeads" :key="index">
          <div class="PageItem">
          <el-row class="PageInfo"><i class="info-bar"></i>逝者信息</el-row>
          <el-row class="paddingleft2em">
            <el-col :span="6">
              <el-form-item label="姓名">
              <el-input
                :value="item.deadName"
                disabled
              >
              </el-input>
            </el-form-item>
            <el-form-item label="　民族">
                 <el-input
                :value="item.deadNationCode"
                disabled
              >
              </el-input>
            </el-form-item>
            <el-form-item label="　 户籍地">
              <el-input
                :value="item.householdRegistrationPlace"
                disabled
              >
              </el-input>
            </el-form-item>
            </el-col>
            <el-col :span="6">
               <el-form-item label="　性别">
              <el-input
                :value="item.deadGenderCode"
                disabled
              >
              </el-input>
               </el-form-item>
               <el-form-item label="　证件类型">
              <el-input
                :value="item.certificateTypeCode"
                disabled
              >
              </el-input>
            </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="　出生日期" >
                <el-input
                :value="item.birthDate"
                disabled
              >
              </el-input>
              </el-form-item>
              <el-form-item label="　证件号码">
                <el-input
                :value="item.certificateNo"
                disabled
              >
              </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="　国籍">
                <el-input
                :value="item.countryCode"
                disabled
              >
              </el-input>
              </el-form-item>
              <el-form-item
                label="　死亡日期"
              >
               <el-input
                :value="item.deathDate"
                disabled
              >
              </el-input>
            </el-form-item>
            </el-col>
          </el-row>
        </div>
        <div class="PageItem">
          <el-row class="PageInfo"><i class="info-bar"></i>经办人信息</el-row>
          <el-row class="paddingleft2em">
            <el-col :span="6">
              <el-form-item label="　姓名">
                <el-input
                :value="item.familyName"
                disabled
              >
              </el-input>
            </el-form-item>
            <el-form-item label="　联系地址">
              <el-input
                v-model="ruleForm.depositBuryAgentEntity.familyAddress"
                maxlength="50"
                class="w1230"
                placeholder="请填写联系地址"
              ></el-input>
            </el-form-item>
            </el-col>
            <el-col :span="6">
               <el-form-item
              label="手机号码"
              prop="depositBuryAgentEntity.familyPhone"
              
            >
              <el-input
                v-model="ruleForm.depositBuryAgentEntity.familyPhone"
                @mousewheel.native.prevent
                onkeyup="value=value.replace(/[^\d]/g,'')"
                maxlength="11"
                placeholder="请填写手机号码"
              ></el-input>
            </el-form-item>
            </el-col>
            <el-col :span='6'>
              <el-form-item
              label="证件类型"
              prop="depositBuryAgentEntity.certificateTypeCode"
              
            >
              <el-select
                v-model="ruleForm.depositBuryAgentEntity.certificateTypeCode"
                @focus="focus"
                @clear="clear"
                clearable
                filterable
                :filter-method="PinyinMatchcertificates"
                placeholder="请选择证件类型"
                class="w150"
              >
                <el-option
                  v-for="item in copydictionary.certificates"
                  :key="item.dataCode"
                  :label="item.dataText"
                  :value="item.dataCode"
                  :disabled="item.disableState"
                />
              </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item
              label="证件号码"
              prop="depositBuryAgentEntity.certificateNo"
              
            >
              <el-input
                v-model="ruleForm.depositBuryAgentEntity.certificateNo"
                maxlength="20"
                placeholder="请填写证件号码"
              ></el-input>
            </el-form-item>
            </el-col>
          </el-row>
        </div>
        </li>
      </ul>
      <span slot="footer" class="dialog-footer">
        <el-button @click="deadInfoDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="deadInfoDialogVisible = false">确 定</el-button>
      </span>
    </el-dialog> -->
    <SearchDialog
      :DialogSearch="DialogSearch"
      :copyCremationTypes="dictionary.cremation_type"
      :userType="userType"
      :excludedCurrentSaveDeadFlag='true'
      :searchHistoryDeadFlag='true'
    ></SearchDialog>
  </div>
</template>
<script>
// import { dataFormate } from "@/utils/index";
import * as Type from "@/api/service";
import SearchDialog from "../dialog/SearchDialogCopy";
// import user from 'mock/user';

export default {
  // props: {
  //   dialogVisible: {
  //     type: Boolean,
  //     default: true,
  //   },
  //   Changeofposition: {
  //     type: Boolean,
  //   },
  // },
  components: {
      SearchDialog,
    },
  data() {
    return {
      useDid:'',//
      dialogVisibles: this.dialogVisible,//
      DialogSearch:false,//搜索弹框
      BuyerInfoDialogVisible:false,//信息弹框
      BuyerInfoFormDisabled:false,//是否禁用
      pickerOptions: {
          disabledDate(time) {
            return time.getTime() >= Date.now();
          },
        },
      selectGWId:0,//选择的格位Id
      isEdit:false,
      isCheck:false,
      ruleForm: {
          funeralDead: {
            deadName: "",
            id: "",
            businessCode: "",
            exemptionTypeCode: "",
            deadGenderCode: "",
            memberName: "",
            certificateTypeCode: "",
            certificateNo: "",
            countryCode: "",
            deadNationCode: "",
            memberGenderCode: "",
            deadAge: "",
            deadAgeTypeCode: "",
            birthDate: "",
            cremationTypeCode: "",
            remainsStateCode: "",
            deathDate: "",
            deathCause: "",
            ashHandleTypeCode: "",
            provinceId: "",
            cityId: "",
            countyId: "",
            provinceCityCountyId: "",
            provinceCityCountyFullName: "",
            townId: "",
            villageId: "",
            beforeDeathAddress: "",
            asLocal: 1,
            householdRegistrationClassCode: "",
            householdRegistrationPlace: "",
            deathCertificateUnit: "",
            funeralCertificateUnit: "",
            asOutwardTransport: "",
            outwardTransportTime: "",
            outwardTransportPlace: "",
            benefitDistrictCode: "",
            remark: "",
            transportWayCode: "",
            transportPlace: "",
            asArrived: "",
            //是否外运
            asOuterTransport: "",
            //外运地址
            outerTransportAddress: "",
            //是否馆外司机
            asOutsideDriver: "",
            //司机id
            driverUserIdr: "",
            transportArrivedTime: "",
            arrivedTime: "",
          },
          depositBuryAgentEntity:{
            familyName:'',//姓名
            familyAddress:'',//地址
            certificateTypeCode:"",//证件类型
            certificateNo:'',//证件号码
            familyPhone:'',//手机号
          },
          images:[]
        }, //表单信息
       rules: {
          "funeralDead.deadName": [
            {
              required: true,
              message: "请输入逝者姓名",
              trigger: "blur",
            },
            {
              min: 1,
              max: 50,
              message: "长度在 1 到 50 个字符",
              trigger: "blur",
            },
          ],
          "funeralDead.certificateTypeCode": [
            {
              required: true,
              message: "请选择逝者证件类型",
              trigger: "change",
            },
          ],
        },//表单校验规格
      treeInfoLoad: [],
      treeData: [],
      data: [],
      defaultProps: {
        children: "children",
        label: "label",
      },
      wakeHalls: [],
      selectname: "",
      lastTreeData: [], //最后一层树的数据
      selectNode:{},//选中的节点
      dictionary: {}, //字典
      copydictionary: {}, //用于检索拼音
      businessCode:'',//业务编码
      businessType:'',//业务类型byg_gw_in、gm_gw_in
      saveDetailedType:'',//保存详细类型byg_gw gm_gw
      grandFather:'',//所选节点的祖父节点、根节点
      //按钮权限
        btnRight: {
          btnAddBuyerInfo: false,
          btnModifyBuryingInfo: false,
          btnCheckBuryingInfo: false,
        }, 
        userType:''
    };
  },
  filters:{
    formatType(val){
      if(val==1){
        return '单格位'
      }else if(val==2){
        return '双格位'
      }else{
        return '未知'
      }
    }
  },
  created(){
    let userType=this.$store.getters.userInfo.organizationType
    if(userType==1){
      //殡仪馆用户
      this.businessType='byg_gw_in';
      this.saveDetailedType='byg_gw'
      this.userType='byg'
      this.useDid=1
    }else if(userType==2){
      //公墓用户
      this.businessType='gm_gw_in';
      this.saveDetailedType='gm_gw';
      this.userType='gm';
      this.useDid=0
    }
  },
  watch: {
    selectNode(newVal,oldVal){
      console.log(newVal.id,'新的节点Id')
      this.grandFather={}
      this.getGrandFather(this.treeInfoLoad,newVal.id)
    }
  },
  mounted() {
    //获取树型结构
    this.getTreedata();
    //加载数据字典
      //没有数据，加载数据
    this.$store
        .dispatch("user/getdictionary")
        .then((res) => {
          //获取字典数据
          this.dictionary = res;
          this.copydictionary = JSON.parse(JSON.stringify(this.dictionary));

          this.$set(this.dictionary, res);
          //获取未知的code
          //获取未知的code
          if (
            this.copydictionary.age_type &&
            this.copydictionary.age_type.length
          ) {
            this.copydictionary.age_type.forEach((item) => {
              if (item.dataText == "未知") {
                this.ageWeizhiFlag = item.dataCode;
              }
            });
          }
          /*判断遗体类型*/
          if (
            this.copydictionary.cremation_type &&
            this.copydictionary.cremation_type.length
          ) {
            this.copydictionary.cremation_type.forEach((item) => {
              if (item.dataText.indexOf("遗体") > -1) {
                this.cremationType = item.dataCode;
              }
            });
          }
        })
        .catch(() => console.log("promise catch err"));
        //按钮权限
      this.btnRight = this.$route.meta.buttons;
      //遍历属性赋值将true与false字符串转换成布尔型的值
      for (var key of Object.keys(this.btnRight)) {
        this.btnRight[key] =
          this.btnRight[key] || this.btnRight[key] == "true" ? true : false;
      }
  },
  methods: {
    //监听弹框关闭事件
    closeDialog(){
     //this.$refs['ruleForm'].resetFields();
     this.ruleForm.depositBuryAgentEntity={
        familyName:'',//姓名
        familyAddress:'',//地址
        certificateTypeCode:"",//证件类型
        certificateNo:'',//证件号码
        familyPhone:'',//手机号
      }
    },
    //获取对应的根节点
    getGrandFather(arr,id){
      console.log(arr,id,'父级传值')
      arr.find(item=>{
        if(item.id===id){
          console.log('查找到相同的',item)
          if(item.parentId===0){
            this.grandFather=item
            return false
          }
          this.getGrandFather(arr,item.parentId)
        }
      })
    },
    //修改安葬信息
    async modifyBuryingInfo(code){
      this.isEdit=true
      this.isCheck=false
      this.BuyerInfoFormDisabled=false
      //获取安葬信息
       let postData = {
        businessCode:code
      };
      this.loading = true;
      const res= await Type["getBuryingInfo"](postData)

      if(res.code===1){
        this.ruleForm.funeralDead=res.data.funeralDeadEntity
        this.ruleForm.depositBuryAgentEntity=res.data.familyAgent
        this.BuyerInfoDialogVisible=true
      }else{
        this.$message("数据读取失败");
      }
    },
    //查看安葬信息
    async checkBuryingInfo(businessCode,inBusinessId,saveId){
      this.isCheck=true
      //获取安葬信息
       let postData = {
        businessCode,
        inBusinessId,
        saveId
      };
      this.loading = true;
      const res= await Type["getBuryingInfo"](postData)

      if(res.code===1){
        this.ruleForm.funeralDead=res.data.funeralDeadEntity
        this.ruleForm.depositBuryAgentEntity=res.data.depositBuryAgentEntity
        this.ruleForm.images=res.data.images
        this.BuyerInfoDialogVisible=true
        this.BuyerInfoFormDisabled=true
      }else{
        this.$message("数据读取失败");
        this.BuyerInfoFormDisabled=false
      }
    },
    //保存表单信息
    saveBuyerInfoFormData(formName){
      this.$refs[formName].validate((valid) => {
          if (valid) {
            if(this.isEdit){
              //编辑修改
              this.changeBuyerFormInfo()
            }else{
              //新增安葬人
               this.addBuyerFormInfo()
            }
           
          } else {
            
            return false;
          }
        });
    },
    //新增安葬人
    async addBuyerFormInfo(){ 
      let postData = {
        businessType:this.businessType,
        depositBuryAgentEntity:this.ruleForm.depositBuryAgentEntity,
        funeralDeadEntity:this.ruleForm.funeralDead,
        id:this.selectGWId,
        saveDetailedType:this.saveDetailedType,
        saveId:this.selectGWId,
        saveType:'gw',
        saveFirstLevel:this.grandFather.id
      };
      this.loading = true;
      const res= await Type["addBuryingInfo"](postData)
      
      if(res.code==1){
        this.$message({
          message: res.message,
          type: 'success'
        });
        //获取列表数据
        this.loadOrganizationListWithParentIdData(this.selectNode);
      }else{
        this.$message("数据读取失败");
      }
    },
    //编辑修改安葬信息
    async changeBuyerFormInfo(){
      let postData = {
        businessType:this.businessType,
        depositBuryAgentEntity:this.ruleForm.depositBuryAgentEntity,
        funeralDeadEntity:this.ruleForm.funeralDead,
        id:this.selectGWId,
        saveDetailedType:this.saveDetailedType,
        saveId:this.selectGWId,
        saveType:'gw',
      };
      this.loading = true;
      const res= await Type["changeBuryingInfo"](postData)
 
      if(res.code==1){
        //this.BuyerInfoDialogVisible=false
        this.isEdit=false
        this.$message({
          message: res.message,
          type: 'success'
        });
        //获取列表数据
        this.loadOrganizationListWithParentIdData(this.selectNode);
      }else{
        this.$message("更新失败")
      }
    },
    //添加安葬信息打开搜索弹框
    addBuyerInfo(id){
    
      this.selectGWId=id
      this.BuyerInfoFormDisabled=true
      this.isCheck=false
      this.DialogSearch=true
    },
    //关闭查询弹框调用搜索方法
    searchData() {
      this.ReadData();
    },
    //根据businessCode数据读取
    ReadData() {
      let postData = {
        businessCode: this.businessCode,
        userType:this.userType,
        useDid:this.useDid
      };
      this.loading = true;
      Type["loadwithbusinesscode"](postData)
        .then((response) => {
       
          if (!response) {
            this.$message("数据读取失败");
            return;
          }
          const {data} = response;
          if (!data) {
            this.loading = false;
            this.$message("数据读取失败");
            return;
          }
         
          if (data.funeralDead) {
            
            this.ruleForm.funeralDead = data.funeralDead;
            
          }
          //承办人回显depositBuryAgentEntity
          if(data.familyAgent){
            this.ruleForm.depositBuryAgentEntity.familyName=data.familyAgent.agentName
            this.ruleForm.depositBuryAgentEntity.familyAddress=data.familyAgent.address
            this.ruleForm.depositBuryAgentEntity.certificateTypeCode=data.familyAgent.certificateTypeCode
            this.ruleForm.depositBuryAgentEntity.certificateNo=data.familyAgent.certificateNo
            this.ruleForm.depositBuryAgentEntity.familyPhone=data.familyAgent.mobilePhone
          }
          this.modify = false;
          // 数据读取成功
          //街道赋值
          this.loading = false;
          this.BuyerInfoDialogVisible=true
        })
        .catch((error) => {
          this.$message(error);
          this.loading = false;
        });
    },
    //拼音或中文检索
    PinyinMatchnation(val) {
      if (val) {
        let result = [];
        this.dictionary.nation.filter((item) => {
          if (item.dataTextAbbr.indexOf(val) != -1) {
            result.push(item);
          } else if (item.dataText && item.dataText.indexOf(val) != -1) {
            result.push(item);
          }
          this.copydictionary.nation = result;
        });
      } else {
        this.copydictionary.nation = JSON.parse(
          JSON.stringify(this.dictionary.nation)
        );
      }
    },
    focus() {
      this.copydictionary = JSON.parse(JSON.stringify(this.dictionary));
    },
    clear() {
      this.copydictionary = JSON.parse(JSON.stringify(this.dictionary));
    },
    PinyinMatchsex(val) {
        if (val) {
          let result = [];
          this.dictionary.sex.filter((item) => {
            if (item.dataTextAbbr.indexOf(val) != -1) {
              result.push(item);
            }
            this.copydictionary.sex = result;
          });
        } else {
          this.copydictionary.sex = JSON.parse(
            JSON.stringify(this.dictionary.sex)
          );
        }
      },
    PinyinMatchcertificates(val) {
      if (val) {
        let result = [];
        this.dictionary.certificates.filter((item) => {
          if (item.dataTextAbbr.indexOf(val) != -1) {
            result.push(item);
          }
          this.copydictionary.certificates = result;
        });
      } else {
        this.copydictionary.certificates = JSON.parse(
          JSON.stringify(this.dictionary.certificates)
        );
      }
    },
    PinyinMatchnationality(val) {
      if (val) {
        let result = [];
        this.dictionary.nationality.filter((item) => {
          if (item.dataTextAbbr.indexOf(val) != -1) {
            result.push(item);
          }
          this.copydictionary.nationality = result;
        });
      } else {
        this.copydictionary.nationality = JSON.parse(
          JSON.stringify(this.dictionary.nationality)
        );
      }
    },
    PinyinMatchagent_type(val) {
        if (val) {
          let result = [];
          this.dictionary.agent_type.filter((item) => {
            if (item.dataTextAbbr.indexOf(val) != -1) {
              result.push(item);
            }
            this.copydictionary.agent_type = result;
          });
        } else {
          this.copydictionary.agent_type = JSON.parse(
            JSON.stringify(this.dictionary.agent_type)
          );
        }
      },
    handleClick(data, checked, node) {
      this.selectNode=data
      if (checked.level === 4 && data.typeCode === 3) {
        this.$refs.organizationtree.setCheckedNodes([data]);

        this.data = this.$refs.organizationtree.getCheckedNodes();
        //获取列表数据
        this.loadOrganizationListWithParentIdData(
          this.data[this.data.length - 1]
        );
      }
    },
    mournSelect(item, index) {
      //在弹出选择礼厅对话框中选择
      let this_select = this;
      if (item.depositCaseState=='1' && this.Changeofposition) {
        this.$message("格位被占用,请选择其他");
        return;
      }

      for (let j = 0; j < this.wakeHalls.length; j++) {
        this.wakeHalls[j].flag = false;
      }
      
      this.wakeHalls[index].flag = !this.wakeHalls[index].flag;
      this.$set(this.wakeHalls, index, this.wakeHalls[index]);
      this.selectname = this.wakeHalls[index];
    },
    determine() {
      this.dialogVisibles = false;
      this.$emit("update:dialogVisible", this.dialogVisibles);
      this.$emit("input", this.selectname);
      this.wakeHalls = [];
    },
    //获取树结构数据
    async getTreedata() {
      await Type["loadDepositCaseTreeList"]({})
        .then((response) => {
          const { data } = response;
          if (!data) {
            this.$message("加载数据失败");
            return;
          }
          let node = {
            id: 0,
            label: "寄存管理",
            children: [],
          };
          this.treeInfoLoad = data;
          node = this.getChildren(node, this.treeInfoLoad);
          let treeArray = new Array();
          treeArray.push(node);
          this.treeData = treeArray;

          this.checkChildren(this.treeData);
          this.loadOrganizationListWithParentIdData(this.lastTreeData[0]);
          console.log("默认加载",this.lastTreeData[0])
          this.selectNode=this.lastTreeData[0]
        })
        .catch((error) => {
          this.$message(error);
        });
    },
    getChildren(node, data) {
      let this_get = this;
      let child = new Array();
      if (this_get.checkIsNode(node, data)) {
        if (data && data.length) {
          data.forEach((item) => {
            if (node.id == item.parentId && item.name) {
              let nodeItem = {
                id: item.id,
                label: item.name,
                typeCode: item.typeCode,
              };
              if (this_get.checkIsNode(nodeItem, data)) {
                if (!nodeItem.children) {
                  nodeItem.children = new Array();
                }
                nodeItem.children.push(this_get.getChildren(nodeItem, data));
              }
              child.push(nodeItem);
            }
          });
          node.children = child;
          return node;
        }
      } else {
        return node;
      }
    },
    checkIsNode(node, data) {
      let flag = false;
      if (data && data.length && data.length > 0) {
        for (let i = 0; i < data.length; i++) {
          if (node.id == data[i].parentId) {
            flag = true;
            return flag;
          }
        }
      }
      return flag;
    },
    //c
    async checkChildren(data) {
      await data.forEach((item) => {
        if (item.children) {
          this.checkChildren(item.children);
        } else {
          this.lastTreeData.push(item);
          return false;
        }
      });
      
    },
    //右侧数据
    loadOrganizationListWithParentIdData({ id, typeCode }) {
      let IdData = {
        id,
        typeCode,
      };
      Type["loadDepositCaseCaseTreeId"](IdData).then((response) => {
        const { data } = response;
        if (!data) {
          this.$message("数据读取失败");
          return;
        }
        this.wakeHalls = data;
        this.BuyerInfoDialogVisible=false
        // this.tableData = data;
        // this.EmployeeList = data;
      });
    },
  },
};
</script>

<style scoped>
.pt20{
  padding-top: 20px;
}
.el_img{
  margin-right: 20px;
  cursor: pointer;
}
.el-dialog__headerbtn .el-dialog__close {
  color: #fff !important;
}

.box-card {
  flex: 0 0 200px;
  display: inline-block;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  margin-bottom: 30px;
  margin-right: 10px;
}

.box-card .item {
  font-size: 16px;
  font-weight: 400;
  line-height: 30px;
  width: 100%;
  height: 90px;
  text-align: left;
  padding: 0 1em;
  border-radius: 5px;
  overflow: hidden;
}
.el-tree{
  min-height: 100%;
}
.item:hover {
  cursor: pointer;
}

.item:last-child {
  margin-bottom: 0px;
}

.item.sale {
  background-color: #ff6040;
}

/* .item.free {
  background: white;
  border: 0.5px solid #ccc;
} */

.item.repair {
  background: yellow;
}

.item.selected {
  background: lightgreen !important;
}

.item h2 {
  height: 30px;
  overflow: hidden;
}
/* 弹框文字白色 */
.PageItem /deep/ .el-dialog__title,
.PageItem /deep/.el-dialog__headerbtn .el-dialog__close {
  color: #fff;
}
.PageContent {
  padding:20px;
}
.PageItem{
  padding:0;
  background:#F6F9FF;
}
.el_row{
  height: 100%;
}
.el_col{
  height: 100%;
  box-sizing: border-box;
}
.right_col{
  background: #fff;
  padding-top: 15px;
}
.list_item{
  margin-bottom: 20px;
  cursor: pointer;
}
.list_item /deep/ .el-card {
  min-height: 166px;
  padding-top: 10px;
  position: relative;
  border-radius: 10px;
}
.list_item /deep/ .el-card .check_more{
  width: 50px;
  height: 50px;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  position: absolute;
  right:10px;
  top:10px;
}
.list_item  .el-card .check_more /deep/ .el-icon-s-help{
  font-size: 30px;
}
.list_item .free{
  background: #37B7FF;
  color: #fff;
}
.list_item .saled{
  background: #A566ED;
  color: #fff;
}
.list_item /deep/ .el-card__body{
  padding:0
}
.list_item  .card_header{
  padding:0 15px;
}
.list_item .card_content{
  /* border-top: 1px solid #ccc; */
  padding:15px;
}
.list_item .card_content .dead_person_conent{
  display: flex;
  align-items: center;
}
.list_item .card_content .dead_person_conent .dead_person{
  flex:1;
  /* padding:10px 0; */
  border-radius: 5px;
}
.list_item .card_content .dead_person_conent .dead_person .dead_btns{
  display: flex;
  align-items: center;
  justify-content: space-around;
}
.has_person{
  background: #A566ED;
  color: #fff;
}
.dead_person .dead_content{
  min-height: 30px;
  /* padding: 4px; */
  line-height: 20px;
  text-indent: 10px;
}
.list_item .item_item{
  display: flex;
  flex-direction: column;
  line-height: 20px;
}
.list_item  .card_footer{
  display: flex;
  width: 100%;
  height: 40px;
  padding:5px 0;
}
.dead_btn{
  flex:1;
  padding:10px 0;
   text-align: center;
}
.list_item  .card_footer .card_footer_splitline{
  width: 1px;
  height: 100%;
  background: #ccc;
}
.list_item  .card_footer .card_footer_item{
  flex:1;
  display: flex;
  justify-content: center;
  align-items: center;
}
.list_wrapper{
  width: 100%;
  height: 100%;
  overflow-y: scroll;
}
.list_wrapper .el-row{
  width: 100%;
}
.item_type{
  line-height: 20px;
}
</style>
